package com.xhj.sportsnews.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.xhj.sportsnews.R;

import java.util.List;

/**
 * Created by XHJ on 2016/12/21.
 */
public class GridViewAdapter extends BaseAdapter{
    private List<String> images;
    private Context context;

    public GridViewAdapter(List<String> images, Context context) {
        this.images = images;
        this.context = context;
    }

    @Override
    public int getCount() {

        return images.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.gridview_item, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }else{
            holder = (ViewHolder) view.getTag();
        }
        Picasso.with(context).load(images.get(i)).into(holder.imageView);
        return view;
    }
    private static class ViewHolder {
        ImageView imageView;

        public ViewHolder(View convertView) {
            super();
            imageView = (ImageView) convertView.findViewById(R.id.gv_item_image);
        }
    }

}
